﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.Common;

namespace QunYing.Web.market
{
    public partial class EditDevice : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtDeviceName.Text = Request["name"].ToString ();
                BindData();
            }
        }

        private void BindData()
        {
            BLL.DeviceInfo info = new BLL.DeviceInfo();
            DataTable dt = info.QueryDeviceInfo(Request["icsa"].ToString());
            if (dt.Rows.Count == 0)
            {
                return;
            }
            txtIcsa.Text = dt.Rows[0]["ICSA编号"].ToString();
            txtBrand.Text = dt.Rows[0]["品牌"].ToString();
            txtType.Text = dt.Rows[0]["型号"].ToString();
            txtSize.Text = dt.Rows[0]["箱体尺寸"].ToString();
            txtFish.Text = dt.Rows[0]["鱼类品种"].ToString();
            txtGrass.Text = dt.Rows[0]["水草品种"].ToString();
            txtAddress.Text = dt.Rows[0]["水族箱地址"].ToString();
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Model.DeviceInfo model = new Model.DeviceInfo();
            model.ICSA编号 = Request["icsa"].ToString ();
            model.鱼类品种 = txtFish.Text.Trim();
            model.水草品种 = txtGrass.Text.Trim();
            model.水族箱地址 = txtAddress.Text.Trim();
            model.品牌 = txtBrand.Text.Trim();
            model.型号 = txtType.Text.Trim();
            model.名称 = txtDeviceName.Text.Trim();
            model.箱体尺寸 = txtSize.Text.Trim();
            BLL.DeviceInfo info = new BLL.DeviceInfo();
            bool b = info.UpdateDevice(model);
            if (b)
            {
                MessageBox.ResponseScript(UpdatePanel1, "alert('修改成功');window.parent.document.location.href='userInfo.aspx';");
            }
            else
            {
                MessageBox.Show(UpdatePanel1, "修改失败!");
            }
        }
    }
}
